package com.situ.javase.week2.day3;

import java.security.PublicKey;

import javax.crypto.interfaces.PBEKey;
import javax.swing.text.StyledEditorKit.ForegroundAction;

import org.junit.Test;
import org.omg.CORBA.PUBLIC_MEMBER;

public class StringDemo {
@Test
public void test1() {
	String str = "java AndroidA";
	System.out.println(str.length());
	char [] array = str.toCharArray();
	char ch = str.charAt(5);
	System.out.println(ch);
	
	
	System.out.println(str.indexOf('A'));
	System.out.println(str.indexOf('Y')); //-1
	System.out.println(str.indexOf('A',6));
	
	 System.out.println(str.indexOf("And"));// 5
	   
	   System.out.println(str.lastIndexOf('A'));// 12
	}
	
@Test
public void test2() {
	 String str = "java AndroidA";
	   System.out.println(str.contains("And"));//true
	   System.out.println(str.startsWith("java"));//true
	   System.out.println(str.startsWith("And", 5));//true
	   System.out.println(str.endsWith("oidA"));//true
	   System.out.println(str.isEmpty());//false
	   System.out.println("".isEmpty());//true
}

@Test
public void test3() {
	//String str = "java And";
	char [] array = {'j','a','v','a','A','n','d'};
	String str = new String(array);
	System.out.println(str);
	char [] charArray= str.toCharArray();
	for(char c : charArray) {
		System.out.print(c + " ");
			/*
			 * for (int i = 0; i < charArray.length; i++) {
			 * System.out.println(charArray[i]);
			 */
		}
	}

	


@Test
public void test5() {	
	String str = "java AndroidA";
	String newStr = str.replace('A','B');
	System.out.println(str);
	System.out.println(newStr);
	
}
		
	@Test
	public void test6() {
	String str = "java AndroidA python";
	String [] array = str.split(" ");//按照空格切割切割
for (int i = 0; i < array.length; i++) {
	System.out.println(array[i]);
}
	}
	@Test   // 识别某个字符后面的
	public void test7() {
   String str = "java AndroidA";
   System.out.println(str.substring(5));//AndroidA  从数组下标第五位开始识别
   System.out.println(str.substring(5, 8));//And   识别数组下标5，6，7位
}

	@Test
	public void test8() {
   String str = "   java AndroidA   ";// 切割首尾的空格
   System.out.println(str);//   java AndroidA  
   System.out.println(str.trim());//java AndroidA
}

	@Test
	public void test9() {
	   String str = "java,Android,Python";
	   String[] array = str.split(",");
	 for (String string : array) {
		System.out.println(string);
	}
		}
	   }

